
#include "mine.h"
#include "stdlib.h"
#include <time.h>
#include <iostream>

using namespace std;

Mine::Mine()
{
    map = NULL;
}


bool Mine::GenerateMap(int in_raw, int in_column, int in_mineNum)
{
    if(false == MallocMemForMap(in_raw, in_column, in_mineNum))
    {
        cout << "error: malloc memory failed!" << endl;
        return false;
    }

    if(false == InitMap())
    {
        cout << "error: init map failed!" << endl;
        return false;
    }

    return true;
}

void Mine::reGenerateMap()
{
    InitMap();
}

int Mine::getMineNumber()
{
    return this->mineNum;
}



bool Mine::MallocMemForMap(int in_raw, int in_column, int in_mineNum)
{
    //非法入参
    if(1 > in_raw || 1 > in_column || 1 > in_mineNum || in_mineNum > in_raw * in_column)
    {
        cout << "error: para error!" << endl;
        return false;
    }
    if(NULL != map)
    {
        for(int i = 0; i < raw; i ++)
        {
            delete map[i];
        }
        delete map;
    }
    map = NULL;

    raw = in_raw;
    column = in_column;
    mineNum = in_mineNum;

    map = new unsigned char*[raw];
    for(unsigned char j = 0; j < raw; j ++)
    {
        map[j] = new unsigned char[column];
    }
    return true;
}



